﻿using HVACWebService.Common;

namespace HVACWebService.Cloud.WeChat
{
    public class WeiXinTemplateMessage
    {
        private static string _templateMessageUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";


        /// <summary>
        /// 发送模板图文
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="temp"></param>
        /// <param name="accTon"></param>
        /// <param name="htmlUrl"></param>
        public string TemplateMessageNoData(string openId,  string temp, string accTon,string htmlUrl)
        {
            var httpWebRequestHelp = new HttpWebRequestHelp();
            var url = string.Format(_templateMessageUrl, accTon);
            var data = "{\"touser\":\"" + openId + "\", " +
                          "\"template_id\":\"" + temp + "\"," +
                            "\"url\":\"" + htmlUrl + "\" ," +
                          "\"data\":{}" +
                         "}";

            return httpWebRequestHelp.PostData(url, data);
        }


        /// <summary>
        /// 发送模板图文
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="message"></param>
        /// <param name="temp"></param>
        /// <param name="accTon"></param>
        public string TemplateMessage(string openId, string message, string temp,  string accTon)
        {
            var httpWebRequestHelp = new HttpWebRequestHelp();
            var url = string.Format(_templateMessageUrl, accTon);
            var data = "{\"touser\":\"" + openId + "\", " +
                          "\"template_id\":\"" + temp + "\"," +

                          "\"data\":{}" +
                         "}";

           return httpWebRequestHelp.PostData(url, data);
        }



        /// <summary>
        /// 发送模板图文
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="message"></param>
        /// <param name="temp"></param>
        /// <param name="sendData"></param>
        /// <param name="accTon"></param>
        public string TemplateMessage(string openId, string message, string temp, string sendData,string accTon)
        {
            var httpWebRequestHelp = new HttpWebRequestHelp();
            var url = string.Format(_templateMessageUrl, accTon);
            var data = "{\"touser\":\"" + openId + "\", " +
                        "\"template_id\":\"" + temp + "\"," +
                        "\"data\":{" + sendData +"}" +
                       "}";

            return httpWebRequestHelp.PostData(url, data);
        }

        /// <summary>
        /// 发送模板图文
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="message"></param>
        /// <param name="temp"></param>
        /// <param name="htmlUrl"></param>
        /// <param name="sendData"></param>
        /// <param name="accTon"></param>
        public string TemplateMessage(string openId, string message, string temp, string htmlUrl, string sendData, string accTon)
        {
            var httpWebRequestHelp = new HttpWebRequestHelp();

            var url = string.Format(_templateMessageUrl, accTon);
            var data = "{\"touser\":\"" + openId + "\", " +
                        "\"template_id\":\"" + temp + "\" ," +
                       "\"url\":\"" + htmlUrl + "\" ," +
                       "\"data\":{" + sendData + "}" +
                       "}";

            return httpWebRequestHelp.PostData(url, data);
        }
    }
}